#include <pic.h>
#include "sad8.h"
#include "plcserialinput.h"
#include "serialout.h"
#include "read_config.h"
#include "string.h"
#include "globalset.h"
#include "comfun.h"
#include "debugshow.h"
#include "serialoutio.h"
#include "str2bcd.h"
#include "chanel2com.h"
#include "comsimple.h"
#include "lampcontrol.h"

extern bank1 byte combuf[cnCombuf_Len];
extern bank2 byte simple_delay_byte;
extern bit      heartbit;
extern bit      lampcon;

byte            com_sample_send(void)
{

   static bank2 byte prog_no = 0;
   static bank2 unsigned byte i = 0;
   static bank2 unsigned int j = 0;

   switch (prog_no)
   {

   case 0:
   	
	  if (0 != simple_delay_byte)
		 goto a1;
	  if (j++ > 60000)
		 lampcon = 1;
	  if (1 == insck_io)
	  {
		 j = 0;
		 lampcon = 0;
		 prog_no = 1;
	  }
	  break;

   case 1:
	  if (j++ > 60000)
		 lampcon = 1;
	  if (0 == insck_io)
	  {
		 j = 0;
		 lampcon = 0;
		 prog_no = 2;
	  }
	  break;

   case 2:
	a1:combuf[0] = 'A';
	  chanel2simplecom();
	  combuf[17] = calu_Sum(combuf + 1, 15);
	  combuf[18] = 'B';
	  prog_no = 3;
	  lampcon = 0;
	  break;

   case 3:
	  if (cnSendStrOver == com_send_buff(combuf, 19))
	  {
		 if (0 == simple_delay_byte)
			prog_no = 0;

		 else
			j=	i = prog_no = 4;
	  }
	  break;

   case 4:
   		if ( j++ > 100)
   		{
	   		
	  if (i++ > simple_delay_byte)
	   prog_no = 0;
		
				j =0;
}
	  break;

   }
	LAMPSET =!( lampcon  ||  heartbit );




return 0;

}
